Involver Developer Network : Chapter 4 - Golden Ticket Sweepstakes
This page last changed on Sep 14, 2011 by kristin.bradley@involver.com.
This chapter covers the development of an application which collects signup data through a form, available for later export by admins. The walkthrough builds on Chapter 3 - it assumes you are familiar with feature blocks and using their built-in javascript helper functions. After completing this chapter you'll be able to add complex sign up forms to your applications. Oceanic Golden Ticket SweepstakesOceanic Golden Ticket Sweepstakes is an example of using a signup form to collect entries for a sweepstakes. One lucky fan on Facebook will be chosen at random for free lifetime travel on Oceanic Airlines. All they have to do is provide their name, e-mail and phone number. Let's get started!
First you'll notice a new Feature Block, signup_form. This feature allows you to easily collect information from users through a form. The data is collected, hosted and available for export at any time by an administrator. More on this export functionality later. You'll also notice there was no configuration step required. The signup form is a simple HTML form. Fields are defined as HTML form fields - text inputs in our example - and a special {% signup_form_submit %} tag generates the form's submit button. No configuration is required. Adding a Custom Success MessageBy default, a standard message is displayed after a user successfully submits their information (shown above). You can customize this success behavior easily. Lets change our application to instead show a message which asks users to come back at a later date to see if they are the lucky winner.
The signup_form Feature Block, like most other Feature Blocks, has attributes you can customize. Here we pass a custom javascript function for it's onsuccess attribute. This is a callback the form makes whenever a form is successfully submitted. Our custom javascript function – showThankYouMessage() – uses the SML Javascript API to hide the signup form and show a hidden div we added which contains our customized thank you message. Adding ValidationA common concern when dealing with forms is ensuring valid user input. Some fields may be mandatory while others must match valid formats. In our Sweepstakes, for example, we probably want to ensure that all fields are filled out by the user & that we are collecting valid e-mail addresses.
{% signup_form onsuccess:"showThankYouMessage();" rules_var:"sweeprules" %} <div><label for="name">Name:</label> <input type="text" name="name"/> </div> <div><label for="email">Email:</label> <input type="text" name="email"/> </div> <div><label for="phone_no">Phone Number:</label> <input type="text" name="phone_no"/> </div> {% signup_form_submit %} {% endsignup_form %} <div id="thank_you_message" style="display:none"> <h2>Thanks for entering! Check back here December 1st to see if you've won.</h2> </div> <script type="text/javascript"> var sweeprules = { email: { required: true, email: true }, name: { required: true }, phone_no: { required: true } } function showThankYouMessage() { sml.get('signup_div').hide(); sml.get('thank_you_message').show(); } </script>
We added a new javascript variable to our template called sweepRules. This object is a simple javascript hash. For each field in our form, we have a corresponding property in the hash. Each property then declares if it is required or needs to be validated. The signup_form Feature Block has an additional attribute which takes the name of a variable with the same structure as our sweepsVar. When the form is submitted, the feature block validates the fields against this special javascript rules variable. Validation in SML signup forms is simple yet very powerful - you can choose from several built-in validations or define your own custom validation logic by declaring your validations in a javascript variable. Adding Fan GatingEntering a sweepstakes for free lifetime travel is an amazing offer. Wouldn't it be great if we could only allow fans of the page to enter the sweepstakes?
is_page_fan is a Global Context Variable which is true if the user is a fan, false if they are not. We combine this variable with the {% if %} and {% else %} tags to show two different experiences - one for fans, the other for non-fans. Fan Gating is a popular technique used in social applications to drive fan growth and reengagement by incentivizing access to exclusive content. Using the is_page_fan Global Context Variable with the {% if %} tag gives you the option to easily fan gate anything in your application. Configuring ExportOur system will save all submitted form data forever - until and unless you use the link in your configuration window to manually delete it. You can export signup data directly from the settings page. For each input that you wish to export, you'll need to add a reporting field under the reporting section. Fields can be added and removed from this section at any time - changes only affect which fields are displayed in the report. Once your reporting fields have been configured, you can export collected signups by clicking the download signups link at any point. Configuring Email NotificationsAlong with self-serve export, you can also configure your form to notify any email address whenever a new signup is collected. A common use case for email notifications is simple integration with third-party systems. Any system that can receive mail can integrate with your signup form! Here is an example of the email: The campaign owner for <Campaign> SML (CampaignID: 169662), <User> (UserID: 1234567), has sent a new signup feature notification. Params: feature_id = 654321 page_id = 16248095488 email = hi@hi.com Next StepsYou've now built an application that collects signup data through a fan gate. Take a look at the links below to read more about the signup form feature block. Add new fields and validations to your form. Experiment with different post-signup behavior. Can you think of other opportunities where fan gating would be a good fit? On to Chapter 5![]() ![]() ![]() ![]() |
![]() |
Document generated by Confluence on Feb 12, 2013 09:09 |